<?php
namespace Home\Controller;
use Think\Controller;
use Common\Service\Wechat;
use Think\Log;

class WechatController extends Controller{

    public function __construct()
    {
        
    } 
    
    public function index(){
        /*@$echoStr = $_GET["echostr"];
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        //$token = TOKEN;
        $token   ='poster';
        $tmpArr = array($token, $timestamp, $nonce);
        // use SORT_STRING rule
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);

        if ($tmpStr == $signature) {
             echo $echoStr;
            exit;
        } else {
            return false;
        }*/
        $we = new Wechat();
        $we->index();
    }

    public function createmenu(){
        $we = new Wechat();
        // https://hw.weixin.qq.com/devicectrl/panel/device-list.html?appid=wx4baf685f99a39b48
        $baseurl = $_SERVER['SERVER_NAME'];
        $menujson = '{
            "button":
            [                
                {
                    "name":"快速学车",
                    "sub_button":
                    [
                        {
                           "type":"view",
                           "name":"赚学费",
                           "url":"http://wx.45tnz.com/home/user/recommend"
                        },
                        {
                            "type":"view", 
                            "name":"我要学车", 
                            "url":"http://wx.45tnz.com/home/user/enroll"
                        }
                    ]
                },

                {
                    "type":"view",
                    "name":"个人中心",
                    "url":"http://wx.45tnz.com/home/member/center"
                },

                {
                    "type":"view",
                    "name":"关于我们",
                    "url":"https://mp.weixin.qq.com/s/x03VZw4C5kAo-SvTG7aP_g"
                }
            ]
        }';
        echo $menujson;
        $rs = $we->createMenu($menujson);
        var_dump($rs);
    }
}
